/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * $Id: EmergencyStopData.hpp,v 1.3 2009-11-06 11:49:29 morsko Exp $
 *
 * \file
 * \brief MaCI - EmergencyStop interface data encoder / decoder
 * \author Matthieu Myrsky <matthieu.myrsky@tkk.fi>
 */
#ifndef _MACI_EMERGENCYSTOPDATA_HPP_
#define _MACI_EMERGENCYSTOPDATA_HPP_
#include "MaCIData.hpp"
#include "EmergencyStopTypes.hpp"
#include <stdio.h>

namespace gim {
  namespace binbag{class CBinBag;}
}

namespace MaCI {
  namespace EmergencyStop {
    
    /** Data Encoder/Decoder for the EmergencyStop Interface.
     *
     * Contains the protocol encoder/decoder for the MaCI-EmergencyStop
     * interface
     */
    class CEmergencyStopData : public MaCI::CMaCIData
    {
    public:
      CEmergencyStopData(void);
      ~CEmergencyStopData();

      /** Copy constructor for EmergencyStopdata.
       */
      CEmergencyStopData(const CEmergencyStopData &aData);


      /** Assignment operator for EmergencyStopdata.
       *
       * Use this with care; each call to this function copies data, 
       * so avoid it if possible.
       */
      CEmergencyStopData &operator=(const CEmergencyStopData &aData);
      

      /** Decode a BinBag container as EmergencyStopData element.
       *
       */
      bool DecodeFrom(gim::binbag::CBinBag *aBinBag = NULL);
      

      /** Reset decoder/Encoder.
       *
       * Resets all fields, except leaves the current BinBag container
       * pointer intact.
       */
      void Reset();
      

      /** Set timestamp element.
       *
       * Sets timestamp element for the container.
       *
       * @param[in] aStamp      Reference to element to copy inside binbag.
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetTimestamp(const Common::TTimestamp &aStamp);

      /** Set Command element.
       *
       * Sets command element for the container.
       *
       * @param[in] aCommand    Reference to element to copy inside binbag.
       * @return                'true' if the element was succesfully added 
       *                        (did not previously exists) or 'false' on error
       *                        or when the element was already set on this session.
       */
      bool SetCommand(const TCommand &aCommand);

      /** Set emergencyStopStatus- struct
       *
       * \see TStatus
       *
       * @param[in] aStatus     Status struct to set.
       * @return                'true' if no such element previously
       *                        exists, and a valid binbag::CBinBag backend exists.
       */
      bool SetEmergencyStopStatus(const TStatus &aStatus);

      /** Set timeout time- struct
       *
       * \see TTimeoutTime
       *
       * @param[in] aTimeoutTime Timeout time to set.
       * @return                'true' if no such element previously
       *                        exists, and a valid binbag::CBinBag backend exists.
       */
      bool SetTimeoutTime(const TTimeoutTime &aTimeoutTime);

      /** Return Common::TTimestamp element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const Common::TTimestamp *GetTimestamp(void) const {
        return iTimestampPtr;
      }

      /** Return TCommand element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TCommand *GetCommand(void) const {
        return iCommandPtr;
      }

      /** Return TStatus element pointer.
       * 
       * @return                Returns pointer to element,
       *                        or NULL if no such element exists in the container.
       */
      const TStatus *GetStatus(void) const {
        return iStatusPtr;
      }

      /** Get constant pointer to timeout time element (if such exists).
       *
       *
       * @return                Constant pointer to Timeout time elements if
       *                        such exists in the container. If the element
       *                        doesn't exist, NULL is returned.
       */
      const TTimeoutTime *GetTimeoutTime(void) const
      {
        return iTimeoutTimePtr;
      }

      /** Print.
       * 
       * \copydoc CMaCIData::Print()
       */
      void Print(const int level) const;

    protected:
    private:
      const Common::TTimestamp *iTimestampPtr; ///< Pointer to timestamp if exists
      const TCommand *iCommandPtr;
      const TStatus *iStatusPtr;
      const TTimeoutTime *iTimeoutTimePtr;
    };
  }
}
#endif
